import request from '@/utils/request.ts'

type  LoginInfo = {
  username:string
  code?:string //可要可不要
  password:string
}

type LoginResult = {
  code:number
  message:string
  data:string
}

//用户请求登录
export const login = (loginInfo:LoginInfo) => {
  return request<LoginResult>({
    url: '/api/user/login',
    method: 'post',
    // data:`username=${loginInfo.username}&password=${loginInfo.password}`
    data: loginInfo
  })
}

//用户信息
export const userInfo = () => {
  return request({
    url: '/api/user/info',
    method: 'get'
  })
}

  /**
   * 要求请求类型 application/x-www-form-urlencoded
   *
   * 需要把数据拼接为格式：data: "属性1=值1&属性2=值2"
   *
   * 要求请求类型 application/json
   *
   * 只需要直接传对象：data: loginInfo: { ... }
   */

export const categoryList = () => {
    return request({
      url: '/api/category/list',
      method: 'get'
  })
}

export const categoryPage = (params:any) => {
  return request({
    url: '/api/category/page',
    method: 'get',
    params: params
  })
}
